package com.zut.blocks.web.controller;

import com.zut.blocks.base.common.CommonResponse;
import com.zut.blocks.base.common.request.GradeRequest;
import com.zut.blocks.base.controller.GenericController;
import com.zut.blocks.base.domain.Grade;
import com.zut.blocks.service.grade.GradeService;
import com.zut.blocks.service.grade.vo.FinalGrade;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * lxd
 * grade api
 */
@RestController
@RequestMapping("/api/grade")
public class GradeApi extends GenericController<Grade, Integer, GradeService> {

    @Resource
    GradeService gradeService;

    @GetMapping
    public CommonResponse<List<FinalGrade>> courseGrade(GradeRequest request) {
        return CommonResponse.success(gradeService.getFinalGradeByCourseId(request));
    }

    @PostMapping("/upload")
    public CommonResponse<Integer> upload(MultipartFile file, Integer courseId) {
        return CommonResponse.success(gradeService.upload(file,courseId));
    }

}
